// 防抖函数 用于搜索框等等
export const debounce = (fn,delay = 500)=> {
    let timer = null;
    if(timer) clearTimeout(timer)
    timer = setTimeout(()=>{
        fn()
        timer = null;
    }, delay)
}


// 节流函数 
export const throttle = (fn,delay = 200)=> {
    let timer = null;
    if(timer) return// 和防抖唯一不同的地方就是这里如果含有定时器不清除
    timer = setTimeout(()=>{
        fn()
        timer = null;
    }, delay)
}